#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int minSubArrayLen(int target, vector<int>& nums) {
    int l = 0, r = 0, n = nums.size();
    int res = INT_MAX, tot = 0;
    while (r < n)
    {
        tot += nums[r++];
        if (tot < target)    continue;
        while (l < n && tot >= target)
            tot -= nums[l++];
        res = min(res, r - l + 1);
    }
    return res == INT_MAX ? 0 : res;
}